package com.um.jdy.mp.station.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.mp.base.entity.vo.StationItemVO;
import com.um.jdy.mp.station.entity.dto.AddressDTO;
import com.um.jdy.mp.station.entity.dto.EditStationDTO;
import com.um.jdy.mp.station.entity.vo.EditStationVO;
import com.um.jdy.mp.station.entity.vo.ParamItemVO;
import com.um.jdy.mp.station.manager.StationManager;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ListParams;
import com.um.springboot.starter.orm.params.PageParams;
import com.um.springboot.starter.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 管理类：站场
 *
 * @author cs
 * 日期 2023/5/24
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "网点管理")
@Validated
@RestController
@RequestMapping("/api/v1/cms/station")
public class StationController extends BaseController<StationManager> {

    /**
     * 列表
     * @param name
     * @return
     */
    @ApiOperation("列表")
    @GetMapping({"list"})
    @SaCheckLogin
    public Response<List<StationItemVO>> list(@ApiParam(value = "站场名称") String name) {
        ListParams params = new ListParams();
        if(!StringUtil.isEmpty(name)){
            params.getCondition().put("s.name", StringUtil.getQueryParam(name));
        }
        return manager.list(params);
    }

    /**
     * 列表
     * @param name
     * @return
     */
    @ApiOperation("分佣商户网点列表")
    @GetMapping({"sharing/list"})
    @SaCheckLogin
    public Response<List<StationItemVO>> getSharingList(@ApiParam(value = "站场名称") String name) {
        ListParams params = new ListParams();
        if(!StringUtil.isEmpty(name)){
            params.getCondition().put("s.name", StringUtil.getQueryParam(name));
        }
        return manager.getSharingStationList(params);
    }

    /**
     * 场地类型列表
     * @return
     */
    @ApiOperation("场地类型列表")
    @GetMapping({"type_list"})
    public Response<List<ParamItemVO>> getTypeList() {
        return manager.getTypeList();
    }


    /**
     * 标签列表
     * @return
     */
    @ApiOperation("标签列表")
    @GetMapping({"label_list"})
    public Response<List<ParamItemVO>> getLabelList() {
        return manager.getLabelList();
    }

    /**
     * 服务设施列表
     * @return
     */
    @ApiOperation("服务设施列表")
    @GetMapping({"service_list"})
    public Response<List<ParamItemVO>> getServiceList() {
        return manager.getServiceList();
    }


    /**
     * 分页列表
     * @param page_no
     * @param page_size
     * @param name
     * @return
     */
    @ApiOperation(value = "分页列表")
    @GetMapping("page")
    @SaCheckLogin
    public Response<Page<StationItemVO>> page(@ApiParam(value = "页码") @NotNull Integer page_no,
                                              @ApiParam(value = "数据量") @NotNull Integer page_size,
                                              @ApiParam(value = "站场名称") String name) {
        PageParams params = new PageParams();
        params.setPageNo(page_no);
        params.setPageSize(page_size);
        if(!StringUtil.isEmpty(name)){
            params.getCondition().put("s.name", StringUtil.getQueryParam(name));
        }
        return manager.page(params);
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @ApiOperation(value = "详情")
    @GetMapping("{id}")
    @SaCheckLogin
    public Response<EditStationVO> get(@ApiParam(value = "站场id") @PathVariable String id) {
        return manager.get(id);
    }

    /**
     * 新增站场
     * @param dto
     * @return
     */
    @ApiOperation(value = "新增")
    @PostMapping()
    @SaCheckLogin
    public Response add(@RequestBody EditStationDTO dto) {
        manager.add(dto);
        return Response.success();
    }

    /**
     * 更新
     * @param device_station_id
     * @param dto
     * @return
     */
    @ApiOperation(value = "更新")
    @PutMapping("{device_station_id}")
    @SaCheckLogin
    public Response update(@ApiParam(value = "站场id") @PathVariable String device_station_id,
                         @RequestBody EditStationDTO dto) {
        manager.update(device_station_id,dto);
        return Response.success();
    }

    /**
     * 删除
     * @param device_station_id
     * @return
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("{device_station_id}")
    @SaCheckLogin
    public Response delete(@ApiParam(value = "站场id") @PathVariable String device_station_id) {
        return manager.delete(device_station_id);
    }

    /**
     * 搜索地址
     *
     * @param param
     * @return
     */
    @ApiOperation(value = "查询地图地址")
    @PostMapping("search_address")
    public Response searchAddress(@RequestBody AddressDTO param) {
        return manager.searchAddress(param);
    }

}
